{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 第二章习题\n",
    "\n",
    "### 一、填空题\n",
    "\n",
    "1.列表的`sort()`方法没有返回值,或者说返回值为_____None___."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2.已知列表 `data=[1,2,30 4]`，那么`data[2:100]`的值为_[30, 4]_______."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3.己知`x=3`和`y=5`,那么执行语句`x,y=y,x`之后，`y`的值为___3_____."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4．已知字典 `data= {'a;97, 'A' :65}`,那么`data.get('a', None)`的值为_97_______."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data= {'a':97, 'A' :65}\n",
    "data.get('a', None)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 二、判断题\n",
    "\n",
    "1.生成器表达式的计算结果是一个元组。`( √   )`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2．包含列表的元组可以作为字典的“键”。`(  ×  )`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3．包含列表的元组不可以作为集合的元素。`(  ×  )`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4．列表的`rindex()`方法返回指定元素在列表中最后一次出现的位置。`(  √  )`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 三、编程题\n",
    "\n",
    "1.输入一个字符串，输出其中每个字符的出现次数。要求使用标准库`collotections`中的`Counter`类,请自行查阅相关用法。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from collections import Counter\n",
    "text = input('请输入一个字符串：')\n",
    "frequencies = Counter(text)\n",
    "print(frequencies)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2．输入一个字符串,输出其中只出现了一次的字符及其下标。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "text = input('请输入一个字符串：')\n",
    "positions = [(ch,index) for index,ch in enumerate(text) \n",
    "             if text.index(ch) == text.rindex(ch)]\n",
    "print(positions)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3．输入一个字符串,输出其中每个唯一字符最后一次出现的下标。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "x = input('请输入字符内容：')\n",
    "d = {}\n",
    "for i in x:\n",
    "    d[i] = d.get(i, 0) + 1\n",
    "for j in d:\n",
    "    if d[j] == 1:\n",
    "        print(x.index(j))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4．输入包含若干集合的列表，输出这些集合的并集。提示:使用`reduce()`函数和`operator`模块中的运算实现多个集合的并集。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from functools import reduce\n",
    "lstA = eval(input(\"请输入一个列表：\"));\n",
    "print(reduce(lambda x, y:x | y, lstA));"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "5．输入一个字符串,检查该字符串是否为回文（正着读和反看读都一样的字符串)，如果是就输出`Yes`，否则输出`No`。要求使用切片实现"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "str1 = input('请输入一个字符串')\n",
    "str2 = str1[::-1]\n",
    "if str1 == str2:\n",
    "    print('YES')\n",
    "else:\n",
    "    print('NO')\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 课本上65页课后习题"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "答案：1. 可迭代对象 答案：2. 4 答案：3. None 答案：4. remove() 答案：5. [6,7,9,11] 答案：6. {}；键；值；键 答案：7. items();key();values() 答案：8. ['dict(zip(a,b))'] 答案：9. b = a[::3] 答案：10. 5 for i in range(10) 答案：11. 不可以"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 12\n",
    "data = ['jaechan','jaechan666','jaechan']\n",
    "print(list(filter(lambda s:len(set(s))/len(s) >0.5,data)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 13\n",
    "def lys(x):\n",
    "    for i in range(2,x):\n",
    "        if x%i==0:\n",
    "            return False\n",
    "        if i==x-1:\n",
    "            return True\n",
    "output = filter(lys,range(2,1001))\n",
    "print(list(output))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "14. 当列表从中间或从头增加或删除元素时，列表对象自动进行内存扩展或收缩，从而保证元素之间没有缝隙，但这涉及到列表元素的大量的移动，效率较低，应尽量从列表尾部进行元素的增加与删除操作以提高处理速度."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[87, 82, 29, 61, 14, 87, 82, 91, 30, 83, 10, 1, 58, 1, 61, 56, 9, 2, 31, 37, 40, 12, 12, 81, 61, 26, 14, 7, 30, 9, 95, 92, 61, 73, 37, 32, 10, 16, 1, 47, 96, 64, 50, 4, 3, 43, 16, 3, 83, 83, 63, 10, 23, 75, 26, 16, 17, 13, 50, 94, 85, 17, 78, 97, 84, 39, 64, 21, 30, 59, 70, 48, 35, 80, 16, 86, 63, 61, 23, 60, 69, 50, 30, 71, 31, 21, 71, 53, 36, 54, 89, 52, 36, 45, 66, 100, 20, 21, 78, 53, 50, 44, 19, 25, 61, 66, 60, 32, 42, 42, 82, 31, 97, 5, 29, 45, 89, 30, 73, 18, 67, 46, 81, 0, 93, 36, 27, 84, 47, 64, 17, 42, 66, 67, 36, 100, 52, 38, 64, 97, 89, 19, 0, 97, 8, 86, 30, 16, 70, 85, 16, 39, 3, 47, 72, 13, 0, 91, 1, 93, 9, 77, 62, 84, 62, 19, 54, 23, 83, 75, 32, 95, 20, 25, 39, 61, 24, 45, 68, 32, 77, 71, 23, 95, 26, 93, 43, 37, 95, 40, 96, 43, 36, 4, 81, 14, 53, 52, 68, 42, 62, 48, 55, 21, 46, 21, 46, 90, 6, 4, 85, 46, 32, 64, 12, 1, 84, 26, 33, 0, 18, 88, 5, 97, 39, 68, 49, 89, 89, 26, 28, 13, 94, 17, 69, 61, 100, 76, 95, 0, 47, 9, 55, 43, 51, 89, 24, 65, 90, 26, 12, 58, 32, 30, 32, 32, 94, 15, 58, 72, 5, 79, 24, 56, 65, 88, 82, 57, 27, 18, 33, 98, 22, 42, 89, 28, 51, 71, 52, 15, 23, 66, 51, 28, 19, 16, 48, 46, 50, 94, 27, 24, 39, 23, 73, 30, 19, 41, 94, 10, 57, 74, 3, 56, 76, 28, 80, 34, 37, 46, 92, 26, 31, 41, 69, 39, 8, 64, 54, 32, 31, 47, 79, 56, 53, 2, 92, 48, 64, 17, 88, 12, 70, 84, 35, 26, 95, 59, 10, 83, 53, 29, 23, 89, 82, 74, 76, 54, 43, 37, 64, 36, 50, 82, 88, 78, 25, 63, 58, 11, 100, 24, 73, 9, 65, 15, 85, 30, 2, 78, 31, 12, 53, 26, 97, 7, 25, 11, 87, 60, 57, 13, 20, 88, 21, 49, 81, 90, 43, 60, 1, 78, 39, 89, 65, 4, 15, 77, 66, 44, 67, 2, 34, 96, 74, 39, 97, 69, 76, 62, 52, 27, 75, 89, 47, 67, 72, 85, 41, 25, 92, 47, 1, 87, 40, 13, 69, 100, 64, 95, 64, 40, 92, 40, 78, 36, 13, 61, 44, 77, 71, 76, 20, 58, 23, 0, 37, 16, 96, 57, 1, 43, 22, 2, 45, 1, 14, 7, 13, 29, 30, 90, 96, 25, 13, 72, 34, 19, 73, 40, 7, 93, 56, 81, 98, 80, 93, 11, 73, 67, 36, 29, 43, 64, 42, 60, 80, 91, 88, 72, 85, 73, 44, 79, 37, 62, 22, 57, 28, 17, 75, 44, 72, 56, 77, 55, 54, 57, 83, 86, 95, 6, 40, 62, 57, 28, 51, 76, 20, 74, 96, 10, 25, 55, 25, 74, 13, 24, 68, 75, 53, 15, 70, 90, 44, 57, 81, 6, 81, 41, 11, 53, 99, 56, 12, 43, 76, 12, 85, 0, 17, 27, 36, 87, 20, 48, 58, 51, 66, 27, 62, 16, 12, 8, 98, 31, 97, 82, 89, 20, 24, 14, 63, 81, 3, 37, 18, 51, 83, 29, 71, 39, 86, 56, 74, 67, 57, 91, 35, 16, 59, 59, 46, 68, 98, 1, 80, 73, 84, 92, 65, 75, 27, 89, 12, 80, 44, 67, 76, 5, 40, 34, 90, 25, 11, 34, 25, 74, 97, 17, 49, 92, 59, 26, 16, 64, 37, 16, 86, 9, 23, 100, 97, 28, 30, 58, 84, 64, 45, 34, 33, 47, 60, 18, 65, 23, 43, 17, 64, 85, 24, 93, 27, 21, 41, 74, 66, 30, 81, 44, 73, 26, 100, 31, 51, 28, 62, 42, 16, 30, 58, 61, 1, 14, 73, 87, 18, 11, 60, 61, 54, 22, 17, 84, 32, 40, 14, 80, 78, 15, 2, 10, 47, 41, 25, 89, 99, 80, 8, 16, 36, 13, 15, 67, 84, 27, 65, 72, 16, 47, 50, 3, 18, 45, 33, 50, 34, 98, 65, 72, 99, 87, 60, 78, 11, 5, 95, 49, 72, 36, 23, 28, 79, 7, 70, 12, 1, 66, 4, 18, 34, 44, 75, 40, 52, 26, 46, 37, 81, 6, 32, 81, 32, 70, 92, 18, 43, 72, 88, 75, 45, 80, 57, 1, 43, 22, 57, 66, 3, 4, 52, 80, 72, 40, 83, 5, 81, 62, 21, 44, 26, 52, 71, 29, 99, 37, 23, 42, 74, 58, 16, 50, 39, 97, 61, 42, 64, 81, 70, 21, 94, 32, 52, 96, 27, 98, 81, 26, 51, 78, 67, 73, 20, 29, 50, 3, 22, 92, 70, 94, 14, 89, 88, 68, 25, 30, 99, 37, 86, 22, 16, 85, 1, 32, 38, 54, 69, 37, 57, 30, 30, 0, 39, 38, 94, 62, 22, 86, 5, 91, 93, 30, 11, 56, 3, 66, 3, 84, 52, 23, 21, 62, 13, 37, 37, 99, 18, 90, 18, 39, 91, 66, 80, 55, 17, 73, 37, 72, 41, 55, 37, 95, 67, 45, 37, 55, 56, 62, 49, 91, 91, 5, 89, 61, 23, 11, 85, 20, 49, 46, 64, 79, 56, 55, 99, 24, 85, 70, 97, 65, 90, 7, 55, 33, 89, 46, 49, 73, 94, 25, 5, 28, 22, 67, 32, 49, 5, 34, 96, 77, 24, 87, 74, 98, 38, 95, 84, 85, 1, 49, 49, 3, 91, 71, 33, 13, 59, 80, 41, 2, 92, 80, 78, 74, 84, 59, 31, 60, 50, 48, 51, 12, 98, 83, 63, 74, 73, 59, 87, 86, 9, 17, 53, 79, 17, 80, 96, 99, 85, 17, 37, 85, 16, 38, 60, 86, 53, 1, 80, 84, 8, 48, 59, 19, 82, 65, 98, 93, 3, 73]\n",
      "87 : 9\n",
      "82 : 8\n",
      "29 : 8\n",
      "61 : 13\n",
      "14 : 8\n",
      "87 : 9\n",
      "82 : 8\n",
      "91 : 9\n",
      "30 : 17\n",
      "83 : 9\n",
      "10 : 7\n",
      "1 : 16\n",
      "58 : 9\n",
      "1 : 16\n",
      "61 : 13\n",
      "56 : 11\n",
      "9 : 7\n",
      "2 : 7\n",
      "31 : 9\n",
      "37 : 19\n",
      "40 : 11\n",
      "12 : 12\n",
      "12 : 12\n",
      "81 : 14\n",
      "61 : 13\n",
      "26 : 14\n",
      "14 : 8\n",
      "7 : 6\n",
      "30 : 17\n",
      "9 : 7\n",
      "95 : 11\n",
      "92 : 10\n",
      "61 : 13\n",
      "73 : 15\n",
      "37 : 19\n",
      "32 : 15\n",
      "10 : 7\n",
      "16 : 18\n",
      "1 : 16\n",
      "47 : 10\n",
      "96 : 9\n",
      "64 : 16\n",
      "50 : 11\n",
      "4 : 6\n",
      "3 : 12\n",
      "43 : 12\n",
      "16 : 18\n",
      "3 : 12\n",
      "83 : 9\n",
      "83 : 9\n",
      "63 : 5\n",
      "10 : 7\n",
      "23 : 14\n",
      "75 : 8\n",
      "26 : 14\n",
      "16 : 18\n",
      "17 : 14\n",
      "13 : 12\n",
      "50 : 11\n",
      "94 : 9\n",
      "85 : 14\n",
      "17 : 14\n",
      "78 : 10\n",
      "97 : 12\n",
      "84 : 13\n",
      "39 : 12\n",
      "64 : 16\n",
      "21 : 10\n",
      "30 : 17\n",
      "59 : 9\n",
      "70 : 9\n",
      "48 : 7\n",
      "35 : 3\n",
      "80 : 15\n",
      "16 : 18\n",
      "86 : 9\n",
      "63 : 5\n",
      "61 : 13\n",
      "23 : 14\n",
      "60 : 10\n",
      "69 : 6\n",
      "50 : 11\n",
      "30 : 17\n",
      "71 : 8\n",
      "31 : 9\n",
      "21 : 10\n",
      "71 : 8\n",
      "53 : 10\n",
      "36 : 11\n",
      "54 : 7\n",
      "89 : 16\n",
      "52 : 10\n",
      "36 : 11\n",
      "45 : 8\n",
      "66 : 11\n",
      "100 : 7\n",
      "20 : 9\n",
      "21 : 10\n",
      "78 : 10\n",
      "53 : 10\n",
      "50 : 11\n",
      "44 : 10\n",
      "19 : 7\n",
      "25 : 13\n",
      "61 : 13\n",
      "66 : 11\n",
      "60 : 10\n",
      "32 : 15\n",
      "42 : 9\n",
      "42 : 9\n",
      "82 : 8\n",
      "31 : 9\n",
      "97 : 12\n",
      "5 : 10\n",
      "29 : 8\n",
      "45 : 8\n",
      "89 : 16\n",
      "30 : 17\n",
      "73 : 15\n",
      "18 : 11\n",
      "67 : 11\n",
      "46 : 10\n",
      "81 : 14\n",
      "0 : 8\n",
      "93 : 8\n",
      "36 : 11\n",
      "27 : 10\n",
      "84 : 13\n",
      "47 : 10\n",
      "64 : 16\n",
      "17 : 14\n",
      "42 : 9\n",
      "66 : 11\n",
      "67 : 11\n",
      "36 : 11\n",
      "100 : 7\n",
      "52 : 10\n",
      "38 : 5\n",
      "64 : 16\n",
      "97 : 12\n",
      "89 : 16\n",
      "19 : 7\n",
      "0 : 8\n",
      "97 : 12\n",
      "8 : 5\n",
      "86 : 9\n",
      "30 : 17\n",
      "16 : 18\n",
      "70 : 9\n",
      "85 : 14\n",
      "16 : 18\n",
      "39 : 12\n",
      "3 : 12\n",
      "47 : 10\n",
      "72 : 12\n",
      "13 : 12\n",
      "0 : 8\n",
      "91 : 9\n",
      "1 : 16\n",
      "93 : 8\n",
      "9 : 7\n",
      "77 : 6\n",
      "62 : 12\n",
      "84 : 13\n",
      "62 : 12\n",
      "19 : 7\n",
      "54 : 7\n",
      "23 : 14\n",
      "83 : 9\n",
      "75 : 8\n",
      "32 : 15\n",
      "95 : 11\n",
      "20 : 9\n",
      "25 : 13\n",
      "39 : 12\n",
      "61 : 13\n",
      "24 : 10\n",
      "45 : 8\n",
      "68 : 6\n",
      "32 : 15\n",
      "77 : 6\n",
      "71 : 8\n",
      "23 : 14\n",
      "95 : 11\n",
      "26 : 14\n",
      "93 : 8\n",
      "43 : 12\n",
      "37 : 19\n",
      "95 : 11\n",
      "40 : 11\n",
      "96 : 9\n",
      "43 : 12\n",
      "36 : 11\n",
      "4 : 6\n",
      "81 : 14\n",
      "14 : 8\n",
      "53 : 10\n",
      "52 : 10\n",
      "68 : 6\n",
      "42 : 9\n",
      "62 : 12\n",
      "48 : 7\n",
      "55 : 9\n",
      "21 : 10\n",
      "46 : 10\n",
      "21 : 10\n",
      "46 : 10\n",
      "90 : 8\n",
      "6 : 4\n",
      "4 : 6\n",
      "85 : 14\n",
      "46 : 10\n",
      "32 : 15\n",
      "64 : 16\n",
      "12 : 12\n",
      "1 : 16\n",
      "84 : 13\n",
      "26 : 14\n",
      "33 : 6\n",
      "0 : 8\n",
      "18 : 11\n",
      "88 : 8\n",
      "5 : 10\n",
      "97 : 12\n",
      "39 : 12\n",
      "68 : 6\n",
      "49 : 10\n",
      "89 : 16\n",
      "89 : 16\n",
      "26 : 14\n",
      "28 : 10\n",
      "13 : 12\n",
      "94 : 9\n",
      "17 : 14\n",
      "69 : 6\n",
      "61 : 13\n",
      "100 : 7\n",
      "76 : 8\n",
      "95 : 11\n",
      "0 : 8\n",
      "47 : 10\n",
      "9 : 7\n",
      "55 : 9\n",
      "43 : 12\n",
      "51 : 9\n",
      "89 : 16\n",
      "24 : 10\n",
      "65 : 10\n",
      "90 : 8\n",
      "26 : 14\n",
      "12 : 12\n",
      "58 : 9\n",
      "32 : 15\n",
      "30 : 17\n",
      "32 : 15\n",
      "32 : 15\n",
      "94 : 9\n",
      "15 : 7\n",
      "58 : 9\n",
      "72 : 12\n",
      "5 : 10\n",
      "79 : 6\n",
      "24 : 10\n",
      "56 : 11\n",
      "65 : 10\n",
      "88 : 8\n",
      "82 : 8\n",
      "57 : 12\n",
      "27 : 10\n",
      "18 : 11\n",
      "33 : 6\n",
      "98 : 9\n",
      "22 : 9\n",
      "42 : 9\n",
      "89 : 16\n",
      "28 : 10\n",
      "51 : 9\n",
      "71 : 8\n",
      "52 : 10\n",
      "15 : 7\n",
      "23 : 14\n",
      "66 : 11\n",
      "51 : 9\n",
      "28 : 10\n",
      "19 : 7\n",
      "16 : 18\n",
      "48 : 7\n",
      "46 : 10\n",
      "50 : 11\n",
      "94 : 9\n",
      "27 : 10\n",
      "24 : 10\n",
      "39 : 12\n",
      "23 : 14\n",
      "73 : 15\n",
      "30 : 17\n",
      "19 : 7\n",
      "41 : 8\n",
      "94 : 9\n",
      "10 : 7\n",
      "57 : 12\n",
      "74 : 12\n",
      "3 : 12\n",
      "56 : 11\n",
      "76 : 8\n",
      "28 : 10\n",
      "80 : 15\n",
      "34 : 9\n",
      "37 : 19\n",
      "46 : 10\n",
      "92 : 10\n",
      "26 : 14\n",
      "31 : 9\n",
      "41 : 8\n",
      "69 : 6\n",
      "39 : 12\n",
      "8 : 5\n",
      "64 : 16\n",
      "54 : 7\n",
      "32 : 15\n",
      "31 : 9\n",
      "47 : 10\n",
      "79 : 6\n",
      "56 : 11\n",
      "53 : 10\n",
      "2 : 7\n",
      "92 : 10\n",
      "48 : 7\n",
      "64 : 16\n",
      "17 : 14\n",
      "88 : 8\n",
      "12 : 12\n",
      "70 : 9\n",
      "84 : 13\n",
      "35 : 3\n",
      "26 : 14\n",
      "95 : 11\n",
      "59 : 9\n",
      "10 : 7\n",
      "83 : 9\n",
      "53 : 10\n",
      "29 : 8\n",
      "23 : 14\n",
      "89 : 16\n",
      "82 : 8\n",
      "74 : 12\n",
      "76 : 8\n",
      "54 : 7\n",
      "43 : 12\n",
      "37 : 19\n",
      "64 : 16\n",
      "36 : 11\n",
      "50 : 11\n",
      "82 : 8\n",
      "88 : 8\n",
      "78 : 10\n",
      "25 : 13\n",
      "63 : 5\n",
      "58 : 9\n",
      "11 : 9\n",
      "100 : 7\n",
      "24 : 10\n",
      "73 : 15\n",
      "9 : 7\n",
      "65 : 10\n",
      "15 : 7\n",
      "85 : 14\n",
      "30 : 17\n",
      "2 : 7\n",
      "78 : 10\n",
      "31 : 9\n",
      "12 : 12\n",
      "53 : 10\n",
      "26 : 14\n",
      "97 : 12\n",
      "7 : 6\n",
      "25 : 13\n",
      "11 : 9\n",
      "87 : 9\n",
      "60 : 10\n",
      "57 : 12\n",
      "13 : 12\n",
      "20 : 9\n",
      "88 : 8\n",
      "21 : 10\n",
      "49 : 10\n",
      "81 : 14\n",
      "90 : 8\n",
      "43 : 12\n",
      "60 : 10\n",
      "1 : 16\n",
      "78 : 10\n",
      "39 : 12\n",
      "89 : 16\n",
      "65 : 10\n",
      "4 : 6\n",
      "15 : 7\n",
      "77 : 6\n",
      "66 : 11\n",
      "44 : 10\n",
      "67 : 11\n",
      "2 : 7\n",
      "34 : 9\n",
      "96 : 9\n",
      "74 : 12\n",
      "39 : 12\n",
      "97 : 12\n",
      "69 : 6\n",
      "76 : 8\n",
      "62 : 12\n",
      "52 : 10\n",
      "27 : 10\n",
      "75 : 8\n",
      "89 : 16\n",
      "47 : 10\n",
      "67 : 11\n",
      "72 : 12\n",
      "85 : 14\n",
      "41 : 8\n",
      "25 : 13\n",
      "92 : 10\n",
      "47 : 10\n",
      "1 : 16\n",
      "87 : 9\n",
      "40 : 11\n",
      "13 : 12\n",
      "69 : 6\n",
      "100 : 7\n",
      "64 : 16\n",
      "95 : 11\n",
      "64 : 16\n",
      "40 : 11\n",
      "92 : 10\n",
      "40 : 11\n",
      "78 : 10\n",
      "36 : 11\n",
      "13 : 12\n",
      "61 : 13\n",
      "44 : 10\n",
      "77 : 6\n",
      "71 : 8\n",
      "76 : 8\n",
      "20 : 9\n",
      "58 : 9\n",
      "23 : 14\n",
      "0 : 8\n",
      "37 : 19\n",
      "16 : 18\n",
      "96 : 9\n",
      "57 : 12\n",
      "1 : 16\n",
      "43 : 12\n",
      "22 : 9\n",
      "2 : 7\n",
      "45 : 8\n",
      "1 : 16\n",
      "14 : 8\n",
      "7 : 6\n",
      "13 : 12\n",
      "29 : 8\n",
      "30 : 17\n",
      "90 : 8\n",
      "96 : 9\n",
      "25 : 13\n",
      "13 : 12\n",
      "72 : 12\n",
      "34 : 9\n",
      "19 : 7\n",
      "73 : 15\n",
      "40 : 11\n",
      "7 : 6\n",
      "93 : 8\n",
      "56 : 11\n",
      "81 : 14\n",
      "98 : 9\n",
      "80 : 15\n",
      "93 : 8\n",
      "11 : 9\n",
      "73 : 15\n",
      "67 : 11\n",
      "36 : 11\n",
      "29 : 8\n",
      "43 : 12\n",
      "64 : 16\n",
      "42 : 9\n",
      "60 : 10\n",
      "80 : 15\n",
      "91 : 9\n",
      "88 : 8\n",
      "72 : 12\n",
      "85 : 14\n",
      "73 : 15\n",
      "44 : 10\n",
      "79 : 6\n",
      "37 : 19\n",
      "62 : 12\n",
      "22 : 9\n",
      "57 : 12\n",
      "28 : 10\n",
      "17 : 14\n",
      "75 : 8\n",
      "44 : 10\n",
      "72 : 12\n",
      "56 : 11\n",
      "77 : 6\n",
      "55 : 9\n",
      "54 : 7\n",
      "57 : 12\n",
      "83 : 9\n",
      "86 : 9\n",
      "95 : 11\n",
      "6 : 4\n",
      "40 : 11\n",
      "62 : 12\n",
      "57 : 12\n",
      "28 : 10\n",
      "51 : 9\n",
      "76 : 8\n",
      "20 : 9\n",
      "74 : 12\n",
      "96 : 9\n",
      "10 : 7\n",
      "25 : 13\n",
      "55 : 9\n",
      "25 : 13\n",
      "74 : 12\n",
      "13 : 12\n",
      "24 : 10\n",
      "68 : 6\n",
      "75 : 8\n",
      "53 : 10\n",
      "15 : 7\n",
      "70 : 9\n",
      "90 : 8\n",
      "44 : 10\n",
      "57 : 12\n",
      "81 : 14\n",
      "6 : 4\n",
      "81 : 14\n",
      "41 : 8\n",
      "11 : 9\n",
      "53 : 10\n",
      "99 : 8\n",
      "56 : 11\n",
      "12 : 12\n",
      "43 : 12\n",
      "76 : 8\n",
      "12 : 12\n",
      "85 : 14\n",
      "0 : 8\n",
      "17 : 14\n",
      "27 : 10\n",
      "36 : 11\n",
      "87 : 9\n",
      "20 : 9\n",
      "48 : 7\n",
      "58 : 9\n",
      "51 : 9\n",
      "66 : 11\n",
      "27 : 10\n",
      "62 : 12\n",
      "16 : 18\n",
      "12 : 12\n",
      "8 : 5\n",
      "98 : 9\n",
      "31 : 9\n",
      "97 : 12\n",
      "82 : 8\n",
      "89 : 16\n",
      "20 : 9\n",
      "24 : 10\n",
      "14 : 8\n",
      "63 : 5\n",
      "81 : 14\n",
      "3 : 12\n",
      "37 : 19\n",
      "18 : 11\n",
      "51 : 9\n",
      "83 : 9\n",
      "29 : 8\n",
      "71 : 8\n",
      "39 : 12\n",
      "86 : 9\n",
      "56 : 11\n",
      "74 : 12\n",
      "67 : 11\n",
      "57 : 12\n",
      "91 : 9\n",
      "35 : 3\n",
      "16 : 18\n",
      "59 : 9\n",
      "59 : 9\n",
      "46 : 10\n",
      "68 : 6\n",
      "98 : 9\n",
      "1 : 16\n",
      "80 : 15\n",
      "73 : 15\n",
      "84 : 13\n",
      "92 : 10\n",
      "65 : 10\n",
      "75 : 8\n",
      "27 : 10\n",
      "89 : 16\n",
      "12 : 12\n",
      "80 : 15\n",
      "44 : 10\n",
      "67 : 11\n",
      "76 : 8\n",
      "5 : 10\n",
      "40 : 11\n",
      "34 : 9\n",
      "90 : 8\n",
      "25 : 13\n",
      "11 : 9\n",
      "34 : 9\n",
      "25 : 13\n",
      "74 : 12\n",
      "97 : 12\n",
      "17 : 14\n",
      "49 : 10\n",
      "92 : 10\n",
      "59 : 9\n",
      "26 : 14\n",
      "16 : 18\n",
      "64 : 16\n",
      "37 : 19\n",
      "16 : 18\n",
      "86 : 9\n",
      "9 : 7\n",
      "23 : 14\n",
      "100 : 7\n",
      "97 : 12\n",
      "28 : 10\n",
      "30 : 17\n",
      "58 : 9\n",
      "84 : 13\n",
      "64 : 16\n",
      "45 : 8\n",
      "34 : 9\n",
      "33 : 6\n",
      "47 : 10\n",
      "60 : 10\n",
      "18 : 11\n",
      "65 : 10\n",
      "23 : 14\n",
      "43 : 12\n",
      "17 : 14\n",
      "64 : 16\n",
      "85 : 14\n",
      "24 : 10\n",
      "93 : 8\n",
      "27 : 10\n",
      "21 : 10\n",
      "41 : 8\n",
      "74 : 12\n",
      "66 : 11\n",
      "30 : 17\n",
      "81 : 14\n",
      "44 : 10\n",
      "73 : 15\n",
      "26 : 14\n",
      "100 : 7\n",
      "31 : 9\n",
      "51 : 9\n",
      "28 : 10\n",
      "62 : 12\n",
      "42 : 9\n",
      "16 : 18\n",
      "30 : 17\n",
      "58 : 9\n",
      "61 : 13\n",
      "1 : 16\n",
      "14 : 8\n",
      "73 : 15\n",
      "87 : 9\n",
      "18 : 11\n",
      "11 : 9\n",
      "60 : 10\n",
      "61 : 13\n",
      "54 : 7\n",
      "22 : 9\n",
      "17 : 14\n",
      "84 : 13\n",
      "32 : 15\n",
      "40 : 11\n",
      "14 : 8\n",
      "80 : 15\n",
      "78 : 10\n",
      "15 : 7\n",
      "2 : 7\n",
      "10 : 7\n",
      "47 : 10\n",
      "41 : 8\n",
      "25 : 13\n",
      "89 : 16\n",
      "99 : 8\n",
      "80 : 15\n",
      "8 : 5\n",
      "16 : 18\n",
      "36 : 11\n",
      "13 : 12\n",
      "15 : 7\n",
      "67 : 11\n",
      "84 : 13\n",
      "27 : 10\n",
      "65 : 10\n",
      "72 : 12\n",
      "16 : 18\n",
      "47 : 10\n",
      "50 : 11\n",
      "3 : 12\n",
      "18 : 11\n",
      "45 : 8\n",
      "33 : 6\n",
      "50 : 11\n",
      "34 : 9\n",
      "98 : 9\n",
      "65 : 10\n",
      "72 : 12\n",
      "99 : 8\n",
      "87 : 9\n",
      "60 : 10\n",
      "78 : 10\n",
      "11 : 9\n",
      "5 : 10\n",
      "95 : 11\n",
      "49 : 10\n",
      "72 : 12\n",
      "36 : 11\n",
      "23 : 14\n",
      "28 : 10\n",
      "79 : 6\n",
      "7 : 6\n",
      "70 : 9\n",
      "12 : 12\n",
      "1 : 16\n",
      "66 : 11\n",
      "4 : 6\n",
      "18 : 11\n",
      "34 : 9\n",
      "44 : 10\n",
      "75 : 8\n",
      "40 : 11\n",
      "52 : 10\n",
      "26 : 14\n",
      "46 : 10\n",
      "37 : 19\n",
      "81 : 14\n",
      "6 : 4\n",
      "32 : 15\n",
      "81 : 14\n",
      "32 : 15\n",
      "70 : 9\n",
      "92 : 10\n",
      "18 : 11\n",
      "43 : 12\n",
      "72 : 12\n",
      "88 : 8\n",
      "75 : 8\n",
      "45 : 8\n",
      "80 : 15\n",
      "57 : 12\n",
      "1 : 16\n",
      "43 : 12\n",
      "22 : 9\n",
      "57 : 12\n",
      "66 : 11\n",
      "3 : 12\n",
      "4 : 6\n",
      "52 : 10\n",
      "80 : 15\n",
      "72 : 12\n",
      "40 : 11\n",
      "83 : 9\n",
      "5 : 10\n",
      "81 : 14\n",
      "62 : 12\n",
      "21 : 10\n",
      "44 : 10\n",
      "26 : 14\n",
      "52 : 10\n",
      "71 : 8\n",
      "29 : 8\n",
      "99 : 8\n",
      "37 : 19\n",
      "23 : 14\n",
      "42 : 9\n",
      "74 : 12\n",
      "58 : 9\n",
      "16 : 18\n",
      "50 : 11\n",
      "39 : 12\n",
      "97 : 12\n",
      "61 : 13\n",
      "42 : 9\n",
      "64 : 16\n",
      "81 : 14\n",
      "70 : 9\n",
      "21 : 10\n",
      "94 : 9\n",
      "32 : 15\n",
      "52 : 10\n",
      "96 : 9\n",
      "27 : 10\n",
      "98 : 9\n",
      "81 : 14\n",
      "26 : 14\n",
      "51 : 9\n",
      "78 : 10\n",
      "67 : 11\n",
      "73 : 15\n",
      "20 : 9\n",
      "29 : 8\n",
      "50 : 11\n",
      "3 : 12\n",
      "22 : 9\n",
      "92 : 10\n",
      "70 : 9\n",
      "94 : 9\n",
      "14 : 8\n",
      "89 : 16\n",
      "88 : 8\n",
      "68 : 6\n",
      "25 : 13\n",
      "30 : 17\n",
      "99 : 8\n",
      "37 : 19\n",
      "86 : 9\n",
      "22 : 9\n",
      "16 : 18\n",
      "85 : 14\n",
      "1 : 16\n",
      "32 : 15\n",
      "38 : 5\n",
      "54 : 7\n",
      "69 : 6\n",
      "37 : 19\n",
      "57 : 12\n",
      "30 : 17\n",
      "30 : 17\n",
      "0 : 8\n",
      "39 : 12\n",
      "38 : 5\n",
      "94 : 9\n",
      "62 : 12\n",
      "22 : 9\n",
      "86 : 9\n",
      "5 : 10\n",
      "91 : 9\n",
      "93 : 8\n",
      "30 : 17\n",
      "11 : 9\n",
      "56 : 11\n",
      "3 : 12\n",
      "66 : 11\n",
      "3 : 12\n",
      "84 : 13\n",
      "52 : 10\n",
      "23 : 14\n",
      "21 : 10\n",
      "62 : 12\n",
      "13 : 12\n",
      "37 : 19\n",
      "37 : 19\n",
      "99 : 8\n",
      "18 : 11\n",
      "90 : 8\n",
      "18 : 11\n",
      "39 : 12\n",
      "91 : 9\n",
      "66 : 11\n",
      "80 : 15\n",
      "55 : 9\n",
      "17 : 14\n",
      "73 : 15\n",
      "37 : 19\n",
      "72 : 12\n",
      "41 : 8\n",
      "55 : 9\n",
      "37 : 19\n",
      "95 : 11\n",
      "67 : 11\n",
      "45 : 8\n",
      "37 : 19\n",
      "55 : 9\n",
      "56 : 11\n",
      "62 : 12\n",
      "49 : 10\n",
      "91 : 9\n",
      "91 : 9\n",
      "5 : 10\n",
      "89 : 16\n",
      "61 : 13\n",
      "23 : 14\n",
      "11 : 9\n",
      "85 : 14\n",
      "20 : 9\n",
      "49 : 10\n",
      "46 : 10\n",
      "64 : 16\n",
      "79 : 6\n",
      "56 : 11\n",
      "55 : 9\n",
      "99 : 8\n",
      "24 : 10\n",
      "85 : 14\n",
      "70 : 9\n",
      "97 : 12\n",
      "65 : 10\n",
      "90 : 8\n",
      "7 : 6\n",
      "55 : 9\n",
      "33 : 6\n",
      "89 : 16\n",
      "46 : 10\n",
      "49 : 10\n",
      "73 : 15\n",
      "94 : 9\n",
      "25 : 13\n",
      "5 : 10\n",
      "28 : 10\n",
      "22 : 9\n",
      "67 : 11\n",
      "32 : 15\n",
      "49 : 10\n",
      "5 : 10\n",
      "34 : 9\n",
      "96 : 9\n",
      "77 : 6\n",
      "24 : 10\n",
      "87 : 9\n",
      "74 : 12\n",
      "98 : 9\n",
      "38 : 5\n",
      "95 : 11\n",
      "84 : 13\n",
      "85 : 14\n",
      "1 : 16\n",
      "49 : 10\n",
      "49 : 10\n",
      "3 : 12\n",
      "91 : 9\n",
      "71 : 8\n",
      "33 : 6\n",
      "13 : 12\n",
      "59 : 9\n",
      "80 : 15\n",
      "41 : 8\n",
      "2 : 7\n",
      "92 : 10\n",
      "80 : 15\n",
      "78 : 10\n",
      "74 : 12\n",
      "84 : 13\n",
      "59 : 9\n",
      "31 : 9\n",
      "60 : 10\n",
      "50 : 11\n",
      "48 : 7\n",
      "51 : 9\n",
      "12 : 12\n",
      "98 : 9\n",
      "83 : 9\n",
      "63 : 5\n",
      "74 : 12\n",
      "73 : 15\n",
      "59 : 9\n",
      "87 : 9\n",
      "86 : 9\n",
      "9 : 7\n",
      "17 : 14\n",
      "53 : 10\n",
      "79 : 6\n",
      "17 : 14\n",
      "80 : 15\n",
      "96 : 9\n",
      "99 : 8\n",
      "85 : 14\n",
      "17 : 14\n",
      "37 : 19\n",
      "85 : 14\n",
      "16 : 18\n",
      "38 : 5\n",
      "60 : 10\n",
      "86 : 9\n",
      "53 : 10\n",
      "1 : 16\n",
      "80 : 15\n",
      "84 : 13\n",
      "8 : 5\n",
      "48 : 7\n",
      "59 : 9\n",
      "19 : 7\n",
      "82 : 8\n",
      "65 : 10\n",
      "98 : 9\n",
      "93 : 8\n",
      "3 : 12\n",
      "73 : 15\n"
     ]
    }
   ],
   "source": [
    "#15.\n",
    "import random\n",
    "x = [random.randint(0,100)for i in range(1000)]\n",
    "print(x)\n",
    "for i in x:\n",
    "    print(i,':',x.count(i))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "输入下标上限1\n",
      "输入下标下限4\n",
      "输入一个列表[1,2,3,4,5,6,7]\n",
      "['1', '2', '3', '4', '5', '6', '7']\n",
      "['2', '3', '4', '5']\n"
     ]
    }
   ],
   "source": [
    "#16.\n",
    "x = int(input(\"输入下标上限\"))\n",
    "y = int(input(\"输入下标下限\"))\n",
    "z = input(\"输入一个列表\")\n",
    "c=z[1:-1].split(\",\")\n",
    "print(c)\n",
    "print(c[x:y+1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "input your thingjaechan\n",
      "您输入的键不存在\n"
     ]
    }
   ],
   "source": [
    "# 17.\n",
    "d = {'li':5,'yu':9,'shi':7}\n",
    "a = input('input your thing')\n",
    "print(d.get(a,'您输入的键不存在'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[20, 27, 42, 44, 50, 73, 76, 76, 78, 91, 94, 89, 89, 87, 84, 80, 66, 31, 20, 1]\n"
     ]
    }
   ],
   "source": [
    "#18.\n",
    "import random\n",
    "s = [random.randint(0,100)for i in range(20)]\n",
    "a = sorted(s[:10])\n",
    "b = sorted(s[10:],reverse = True)\n",
    "x = a+b\n",
    "print(x)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": false,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "165px"
   },
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
